// import * as THREE from 'three'
import { ObjMaterial, ObjMaterial07 } from '../../materal'
import * as THREE from 'three'
import { Tooltip } from './tooltip'
import { IOT } from './IOT'
export class Objs {
  constructor(name) {
    this.eventGroup = []
    this.eventMap = []
    this.name = name
    this.instance = new THREE.Object3D()
    this.mesh = null
    this.data = null
    this.id = null
    this.materialList = [ObjMaterial, ObjMaterial07]
  }
  load(mesh, data) {
    mesh.material = ObjMaterial07
    mesh.name = this.name
    this.instance.add(mesh)
    this.mesh = mesh
    // // 添加弹窗
    // this.addTooltip(data)
    return mesh
  }
  // 设置不同位置
  setPoistion(x, y, z) {
    this.instance.position.set(x, y, z)
  }
  // 根据type选择不同贴图
  changeMeshMaterial(type) {
    this.mesh.material = this.materialList[type]
  }
  // 添加信息弹窗
  addTooltip(data) {
    this.data = data
    // 把名字传入data
    this.tooltip = new Tooltip()
    this.instance.add(this.tooltip.instance)
    // 处理数据把name去掉
    const name = data.name
    this.id = data.id
    delete data.name
    delete data.id
    this.tooltip.draw(data, name)
    this.unhandleSelected()
  }
  // 添加传感器等
  addIOT(camera, data) {
    // 遍历数据添加iot设备
    data.forEach(itemData => {
      const iot = new IOT(camera, itemData)
      this.instance.add(iot.instance)
      this.eventGroup.push(iot.circle)
      this.eventMap[itemData['name']] = iot
    })
    // geometry2.lookAt(camera.position)
    // this.instance.add(circle4)
  }
  // 选中时
  handleSelected() {
    this.tooltip.show()
    // this.changeMeshMaterial(0)
  }
  // 未选中时
  unhandleSelected() {
    this.tooltip.hide()
    // this.changeMeshMaterial(1)
  }
  animate() {
  }
}
